console.log('hello zijie')
// const a = 'sdk'
// let i = 0
/* for(let i = 0;i < 5;i++){
    setTimeout(()=>{
        console.log(i)
    })
} */
/* function repeat(fn,count,delay){
    let innerCount = count
    return function(str){
        let that = this
        let s = setInterval(()=>{
            if(innerCount === 0){
                clearInterval(s)
                return
            }
            fn.call(that,str)
            innerCount--
        },delay)
    }
}
const repeatFunc = repeat(console.log, 4, 3000)
repeatFunc("helloworld") */
/* var scope = 'global'
function test(){
    console.log(scope)
    var scope = '2'
    console.log(scope)
}
test() */

/* function MyInstantof(a,b){
    let temp = a
    let res = false
    while(a){
        if(temp.__proto__ === b.prototype){
            res = true
            break
        }else{
            temp = temp.__proto__
        }
    }
    return res
}
let arr = [1,2,3]
console.log(MyInstantof(arr,Object)) */
/* let b = undefined
let a = b || []
console.log(a)
let obj = {name:'f',age:20}
let {name,age} = obj
name = 'd'
console.log(name,age)
console.log({...obj}) */

// 闭包
/* let scope = 'global'
function test(){
    let scope = 'local'
    function f(){
        return scope
    }
    return f
}
console.log(test()()) */

// 实现一个map
/* Array.prototype.map = function(fn){
    let that = this
    let res = []
    for(let i = 0; i < that.length; i++){
        res.push(fn(that[i],i))
    } 
    return res
}
let a = [1,2,4]
let b = a.map((item,index)=>{
    return item+1
})
console.log(a,b) */

/* window.onload = function(){
    // 比较图片相对于文档本身顶部的高度
    console.log('页面加载完成')
    let imgList = document.querySelectorAll('img')
    // 屏幕可视区域的高度
    let visiableHeight = document.documentElement.clientHeight
    //滚动区域滚动的高度
    
    function GetTop(img){
        let re = 0
        while(img){
            re += img.offsetTop
            img = img.offsetParent
        }
        return re
    }
    window.onscroll = function(){
        let scrollHeight = document.documentElement.scrollTop
        for(let i = 0; i < imgList.length; i++){
            if(GetTop(imgList[i]) < visiableHeight + scrollHeight){
                console.log(imgList[i]['data-src'])
                imgList[i].src = imgList[i].getAttribute('data-src')
                console.log('图片'+ i,)
            }
        }
    }

} */







// 实现比较两个一维对象的比较
/* let objA = {name:'f',age:20}
let ojbB = {name:'f',age:20}

let keys = Object.keys(objA)
let res = true
for(let i = 0; i < keys.length; i++){
    if(ojbB[keys[i]] != objA[keys[i]]){
        res = false
        break
    }
}
console.log(res) */

/* // 原型链继承
function Person(name,age){
    this.name = name
    this.age = age
}
Person.prototype.say = function(){
    console.log('我是'+this.name)
}

function Student(name,age,goal){
    this.goal = goal
    Person.call(this,name,age)
}
Student.prototype.constructor = Student
Student.prototype = new Person()
let s = new Student('hh',20,100)
console.log('s',s) */

// 实现一个new的操作
/* function Person(name,age){
    this.name = name
    this.age = age
}

function _new(){
    let obj = {}
    let con = Array.prototype.shift.call(arguments)
    console.log(con)
    obj.__proto__ = con.prototype
    con.call(obj,...arguments)
    return obj

}

let p = _new(Person,'f',12)
console.log(p) */